﻿Public Class EmpresaFormCadastro
    Inherits System.Web.UI.UserControl

    Public Event Inserir(ByVal empresa As Empresa)

    Public Event Alterar(ByVal empresa As Empresa)

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub GravarClickHandles() Handles ToolbarFormularioCadastro1.Gravar
        Try
            If Me.txtId.Text.Equals("") Then
                RaiseEvent Inserir(Me.CarregarEmpresa)
            Else
                RaiseEvent Alterar(Me.CarregarEmpresa)
            End If
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Protected Sub CancelarClickHandles() Handles ToolbarFormularioCadastro1.Cancelar
        Me.DesabilitaFormulario()
    End Sub

    Private Function CarregarEmpresa() As Empresa
        Try
            Dim empresa As New Empresa
            If Not Me.txtId.Text.Equals("") Then
                empresa.EmpresaId = Convert.ToInt32(txtId.Text)
            End If
            empresa.Titulo = txtTitulo.Text
            empresa.Conteudo = txtConteudo.Text
            Return empresa
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    Public Sub CarregarFormulario(ByVal e As Empresa)
        Me.txtId.Text = e.EmpresaId
        Me.txtTitulo.Text = e.Titulo
        Me.txtConteudo.Text = e.Conteudo
        Me.Visible = True
    End Sub

    Public Sub AbilitarFormulario()
        Me.txtId.Text = String.Empty
        Me.txtTitulo.Text = String.Empty
        Me.txtConteudo.Text = String.Empty
        Me.Visible = True
    End Sub

    Sub DesabilitaFormulario()
        Me.Visible = False
    End Sub

End Class
